package com.yxl.service;

import com.spring.BeanPostProcessor;
import com.spring.Component;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Classname YxlBeanPostProcessor
 * @Description TODO
 * @Date 2023-04-03 14:50
 * @Created by yxl
 */
@Component
public class YxlValueBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {
        for (Field field : bean.getClass().getDeclaredFields()) {
            if(field.isAnnotationPresent(YxlValue.class)){
                field.setAccessible(true);
                try {
                    field.set(bean,field.getAnnotation(YxlValue.class).value());
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
        // bean
        return bean;
    }
}
